<?php
/**
* Model Class
* 
* @author Guillermo Landín
* @link 
*/ 

class Faqmodel extends Model {

    function __construct()
    {
        parent::Model();
        
        $this->CI =& get_instance(); 
    }
    
    function get_faq(){
    
         $this->db->select('id_FAQs, Title_FAQs, Description_FAQs')
                ->from('faqs')
                ->where('Active_FAQs', 1)
                ->order_by('Title_FAQs');            

        $query = $this->db->get();

        return $query->result_array();
    
    }
    
    public function get_item($id = NULL){

        $this->db->select('id_FAQs, Title_FAQs, Description_FAQs')
                ->from('faqs')
                ->where('id_FAQs', $id)
                ->where('Active_FAQs', 1);       

        $query = $this->db->get();

        return $query->row_array();

    }



/***********************************
*   Backoffice functions
***********************************/

    //returns the list of faq
    function admin_get_list($fields='*'){
    
        $this->db->select($fields)
                ->from('faqs')
                ->order_by('Title_FAQs', 'ASC');  

        $query = $this->db->get();

        $result = $query->result_array();
                                 
        return $result;

    }  
    public function admin_get_item($id=FALSE, $fields='*'){

        $this->db->select($fields)
                ->from('faqs')       
                ->where('id_FAQs', $id);  
        
        $query = $this->db->get();
        return $query->row_array();

    }  
    public function admin_update($id=FALSE, $data=array()){

        $this->db->where('id_FAQs', $id)
                ->update('faqs', $data); 

    }                      
    public function admin_insert($data=array()){

        $data["id_FAQs"] = uniqid();
        $data["Active_FAQs"] = 0;
        $this->db->insert('faqs', $data); 
        return $data["id_FAQs"];

    }  
    public function admin_delete($id=FALSE){

        $this->db->where('id_FAQs', $id);
        $this->db->delete('faqs'); 

    } 
    public function is_duplicated($field, $value, $id=FALSE)
    {
    
        $this->db->select('count(1) as counter')
                ->from('faqs')
                ->where($field, $value);        
        if($id!==FALSE) $this->db->where('id_FAQs !=', $id);
    
        $query = $this->db->get();
        $row = $query->row_array();
        if($row == NULL)
            return FALSE;
        
        if($row["counter"] > 0){
            return TRUE;
        }else{
            return FALSE;
        }

    } 
 
}
    
    
/* End of file newsmodel.php */
/* Location: ./system/application/models/newsmodel.php */ 
